import { reqAddressInfo,reqShopInfo, reqMockUserDefaultAddressInfo } from '../../api';
const actions = {
  // 获取用户地址信息 （自己mock的数据）
  async getAddressInfo({commit}){
    let result = await reqMockUserDefaultAddressInfo()
    // console.log('用户地址信息',result)
    if(result.code === 200){
      commit('GETADDRESSINFO',result.data)
    }
  },

  // 获取用户地址信息
  // async getAddressInfo({commit}){
  //   let result = await reqAddressInfo()
  //   console.log('用户地址信息',result)
  //   if(result.code === 200){
  //     commit('GETADDRESSINFO',result.data)
  //   }
  // },

  // 获取用户商品信息
  async getShopInfo({commit}){
    let result = await reqShopInfo()
    // console.log('---------------------getShopInfo',result)
    if(result.code === 200){
      commit('GETSHOPINFO',result.data)
    }
  }
}
const mutations = {
  GETADDRESSINFO(state,data){
    // console.log('-------',a)
    state.addressInfo = data
  },
  GETSHOPINFO(state,shopInfo){
    state.shopInfo = shopInfo
  }
}
const state = {
  addressInfo: [],
  shopInfo:{}
}
const getters = {
  // 简化用户地址信息
  addressInfo(state){
    return state.addressInfo || []
  },
  // 简化商品信息
  shopInfo(state){
    return state.shopInfo.orderDetailVoList || []
  },
  // 获取商品的总价格和数量
  shopPriceAndNum(state){
    return state.shopInfo || {}
  }

}

export default {
  namespaced:true,
  actions,
  mutations,
  state,
  getters
}
